package net.esj.basic.dao.jdbc.jpa.support;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import net.esj.basic.dao.jdbc.jpa.ResultSetExtractor;

public class MapResultSetExtractor implements ResultSetExtractor{

	public Object extractData(ResultSet resultset) {
		if (resultset == null) {
			return null;
		}
		Map rsMap = new IgnoreCaseMap();
		int columnCount;
		try {
			java.sql.ResultSetMetaData metaData = resultset.getMetaData();
			columnCount = metaData.getColumnCount();
			for (int i = 0; i < columnCount; i++) {
				String colName = metaData.getColumnName(i + 1);
				rsMap.put(colName, resultset.getObject(i + 1));
			}
		} catch (SQLException e) {
			throw new RuntimeException(e.getMessage(), e);
		}
		return rsMap;
	}

}
